﻿namespace Sai.Core.Introspection
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;

    public class InstanceConstructorDeclaration : TypeMember, ISourceCodeProvider, IExactlyMatch<InstanceConstructorDeclaration>, ILooselyMatch<InstanceConstructorDeclaration> 
	{
		public InstanceConstructorDeclaration(TypeName typeName)
			: base(typeName)
		{
		}

		public InstanceConstructorDeclaration(TypeName typeName, ObsoleteMarker obsolete)
			: base(typeName, obsolete)
		{
			this.Signature = new Signature();
		}

		public InstanceConstructorDeclaration(TypeName typeName, ObsoleteMarker obsolete, IList<Parameter> parameters)
			: base(typeName, obsolete)
		{
			this.Signature = new Signature(typeName.Name, parameters);
		}

		public Signature Signature { get; set; }

		public bool IsDefault
		{
			get
			{
				return this.Signature.ParameterCount == 0;
			}
		}

		public void Add(Parameter parameter)
		{
			this.Signature.Add(parameter);
		}

		public override string ToString()
		{
            return this.Signature.ToString();
		}

        public SourceCode ToCode()
        {
            SourceCode code = new SourceCode();

            code.Add(this.TypeName.ToCode());
            code.Add(new PunctuationTag("("));
            code.Add(this.Signature.ToCode());
            code.Add(new PunctuationTag(")"));

            return code;
        }

        public bool ExactMatchFor(InstanceConstructorDeclaration other)
        {
            return this.Signature.ExactMatchFor(other.Signature);
        }

        public bool LooseMatchFor(InstanceConstructorDeclaration other)
        {
            return this.Signature.LooseMatchFor(other.Signature);
        }
    }
}
